package com.pay.common.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class Swagger2 {
	@Value("${swagger.service.enabled:true}")
	private Boolean enabled;

	@Bean
	public Docket webApi() {
		return new Docket(DocumentationType.SWAGGER_2).enable(enabled)
				.select().apis(RequestHandlerSelectors.any())
				.paths(PathSelectors.ant("/pay/**")).build()
				.groupName("管理后台API接口文档")
				.pathMapping("/").apiInfo(apiInfo());
	}

	@Bean
	public Docket aliPayApi() {
		return new Docket(DocumentationType.SWAGGER_2).enable(enabled)
				.select().apis(RequestHandlerSelectors.any())
				.paths(PathSelectors.ant("/aliPay/**")).build()
				.groupName("支付宝API接口文档")
				.pathMapping("/").apiInfo(apiInfo());
	}

	@Bean
	public Docket wxPayApi() {
		return new Docket(DocumentationType.SWAGGER_2).enable(enabled)
				.select().apis(RequestHandlerSelectors.any())
				.paths(PathSelectors.ant("/wxPay/**")).build()
				.groupName("微信API接口文档")
				.pathMapping("/").apiInfo(apiInfo());
	}


	@Bean
	public Docket wxMobilePayApi() {
		return new Docket(DocumentationType.SWAGGER_2).enable(enabled)
				.select().apis(RequestHandlerSelectors.any())
				.paths(PathSelectors.ant("/weixinMobile/**")).build()
				.groupName("微信H5接口文档")
				.pathMapping("/").apiInfo(apiInfo());
	}


	@Bean
	public Docket unionPayApi() {
		return new Docket(DocumentationType.SWAGGER_2).enable(enabled)
				.select().apis(RequestHandlerSelectors.any())
				.paths(PathSelectors.ant("/unionPay/**")).build()
				.groupName("银联API接口文档")
				.pathMapping("/").apiInfo(apiInfo());
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("支付系统 官网：https://zzipay.vip")
				.description("微信、支付宝、银联支付服务")
				.termsOfServiceUrl("http://zzipay.vip")
				.contact(new Contact("笔记 ", "http://zzipay.vip", "1178266296@qq.com"))
				.version("1.0").build();
	}
}